<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>

    <script>
      window.onload = function () {
        // 为 div 绑定单击事件
        var div1 = document.getElementById("div1");
        div1.onclick = function () {
          div1.style.backgroundColor = "red";
        };
      };
    </script>
    <style>
      .div1 {
        width: 100px;
        height: 100px;
        background-color: green;
      }
    </style>
  </head>
  <body>
    <div id="div1" class="div1"></div>
  </body>
</html>
